package com.riguz.forks.framework;

import javax.sql.DataSource;

import com.riguz.forks.framework.db.PoolManager;
import com.riguz.forks.framework.db.impl.HikariPoolManager;
import com.riguz.forks.framework.mvc.ExceptionHandler;
import com.riguz.forks.framework.mvc.HandlerInvoker;
import com.riguz.forks.framework.mvc.ViewResolver;
import com.riguz.forks.framework.mvc.impl.DefaultExceptionHandler;
import com.riguz.forks.framework.mvc.impl.DefaultHandlerInvoker;
import com.riguz.forks.framework.mvc.impl.DefaultViewResolver;
import com.riguz.forks.framework.plugin.PluginLoader;
import com.riguz.forks.framework.plugin.impl.DefaultPluginLoader;
import com.riguz.forks.framework.route.Route;
import com.riguz.forks.framework.route.RouteLoader;
import com.riguz.forks.framework.route.impl.DefaultRouteLoader;
import com.riguz.forks.framework.route.impl.RadixTreeRoute;
import com.zaxxer.hikari.HikariDataSource;

public final class Framework {
    public static final String ENCODING           = "UTF-8";
    public static final String ROUTE_SETTINGS     = "routes.yaml";
    public static final String FRAMEWORK_SETTINGS = "framework.yaml";

    public static final String JSP_PATH = "/WEB-INF/jsp";

    public static final String CACHE_ROUTE             = "FORKS_ROUTE";
    public static final String CACHE_ROUTELOADER       = "FORKS_ROUTE_LOADER";
    public static final String CACHE_INVOKER           = "FORKS_HANDLER_INVOKER";
    public static final String CACHE_VIEW_RESOLVER     = "FORKS_VIEW_RESOLVER";
    public static final String CACHE_EXCEPTION_HANDLER = "FORKS_EXCEPTION_HANDLER";
    public static final String CACHE_POOL_MANAGER      = "FORKS_POOL_MANAGER";
    public static final String CACHE_PLUGIN_LOADER     = "FORKS_PLUGIN_LOADER";

    public static Route getRoute() {
        return BeanFactory.getInstance(Framework.CACHE_ROUTE, RadixTreeRoute.class);
    }

    public static RouteLoader getRouteLoader() {
        return BeanFactory.getInstance(Framework.CACHE_ROUTELOADER, DefaultRouteLoader.class);
    }

    public static HandlerInvoker getHandlerInvoker() {
        return BeanFactory.getInstance(Framework.CACHE_INVOKER, DefaultHandlerInvoker.class);
    }

    public static ViewResolver getViewResolver() {
        return BeanFactory.getInstance(Framework.CACHE_VIEW_RESOLVER, DefaultViewResolver.class);
    }

    public static ExceptionHandler getExceptionHandler() {
        return BeanFactory.getInstance(Framework.CACHE_EXCEPTION_HANDLER, DefaultExceptionHandler.class);
    }

    public static PoolManager getPoolManager() {
        return BeanFactory.getInstance(Framework.CACHE_POOL_MANAGER, HikariPoolManager.class);
    }

    public static PluginLoader getPluginLoader() {
        return BeanFactory.getInstance(Framework.CACHE_PLUGIN_LOADER, DefaultPluginLoader.class);
    }

    public static final Class<? extends DataSource> dataSourceClass = HikariDataSource.class;
}
